package org.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.pojo.DApartment;
import org.example.pojo.DApartmentType;
import org.example.pojo.DAsset;
import org.example.pojo.DStaff;
import org.example.pojo.select.DApartmentSelect;
import org.example.service.DApartmentService;
import org.example.utils.Result;
import org.springframework.beans.AbstractNestablePropertyAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;

import java.util.List;
import java.util.Map;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("apartment")
@Tag(name = "房间数据API",description = "Apartment Controller")
public class DApartmentController {

    @Autowired
    private DApartmentService dApartmentService;

    /**
     * 搜索全部房间信息
     * @param dApartmentSelect 搜索值
     * @return 房间信息携带入住人员信息
     */
    @Operation(summary = "获取全部房间信息")
    @PostMapping("/selectAll")
    public Result<Map> selectAll(@RequestBody DApartmentSelect dApartmentSelect){
        return dApartmentService.SelectAllApartmentStaffs(dApartmentSelect);
    }

    /**
     * 单一宿舍搜索
     * @param dApartmentSelect 搜索条件
     * @return 搜索结果
     */
    @Operation(summary = "获取指定宿舍信息")
    @PostMapping("/selectOne")
    public Result<DApartment> selectOne(@RequestBody DApartmentSelect dApartmentSelect){
        return dApartmentService.SelectOneApartmentStaffs(dApartmentSelect);
    }

    /**
     * 搜索全部房间信息
     * @return 房间信息携带入住人员信息
     */
    @Operation(summary = "搜索全部房间信息")
    @PostMapping("/selectApartmentInfo")
    public Result<List<DApartment>> SelectApartmentInfo(){
        return dApartmentService.SelectApartmentInfo();
    }

    /**
     * 更改宿舍信息
     * @param dApartment 宿舍信息
     * @return 更新结果
     */
    @Operation(summary = "更改宿舍信息")
    @PostMapping("/updateApartment")
    public Result<DApartment> updateApartment(@RequestBody DApartment dApartment){
        return dApartmentService.updateApartment(dApartment);
    }

    /**
     * 通过房间类型搜索
     * @param dApartment 携带房间类型
     * @return 搜索出的房间
     */
    @Operation(summary = "通过房间类型搜索")
    @PostMapping("/SelectApartmentTypeApi")
    public Result<Map> SelectApartmentTypeApi(@RequestBody DApartment dApartment){
        return dApartmentService.SelectApartmentTypeApi(dApartment);
    }

    /**
     * 搜索宿舍剩余床位
     * @param dApartment 宿舍
     * @return 剩余床位数量
     */
    @Operation(summary = "搜索宿舍剩余床位")
    @PostMapping("/selectVacancyByApartmentId")
    public Result<Integer> SelectVacancyByApartmentId(@RequestBody DApartment dApartment){
        return dApartmentService.SelectVacancyByApartmentId(dApartment);
    }

    /**
     * 添加宿舍房间
     * @param dApartmentSelect 添加的房间
     * @return 无
     */
    @Operation(summary = "添加宿舍房间")
    @PostMapping("/addApartments")
    public Result<Map> AddApartments(@RequestBody DApartmentSelect dApartmentSelect){
        return dApartmentService.AddApartments(dApartmentSelect);
    }

    /**
     * 删除宿舍房间
     * @param dApartment 需删除的房间
     * @return 无
     */
    @Operation(summary = "删除宿舍房间")
    @PostMapping("/deleteApartment")
    public Result<Map> DeleteApartment(@RequestBody DApartment dApartment){
        return dApartmentService.DeleteApartment(dApartment);
    }

    /**
     * 统计宿舍信息
     * @return
     */
    @Operation(summary = "宿舍统计数据")
    @PostMapping("/staticApartment")
    public Result<Map> StaticApartment(){
        return dApartmentService.StaticApartment();
    }

    /**
     * 获取宿舍类型
     */
    @Operation(summary = "获取宿舍类型")
    @PostMapping("/selectApartmentType")
    public Result<List<DApartmentType> > SelectApartmentType(){
        return dApartmentService.SelectApartmentType();
    }


    /**
     * 同步全部宿舍剩余人数
     */
    @Operation(summary = "同步全部宿舍剩余人数")
    @GetMapping("/syncVacany")
    public Result<Map> SyncVacancy(){
        return dApartmentService.SyncVacancy();
    }

    /**
     * 搜索指定宿舍的资产
     * @param DAsset 搜索条件
     * @return 搜索结果
     */
    @Operation(summary = "搜索指定宿舍的资产")
    @PostMapping("/selectAssetByApartmentId")
    public Result<List<DAsset>> SelectAssetByApartmentId(@RequestBody DAsset DAsset){
        return dApartmentService.SelectAssetByApartmentId(DAsset);
    }

    /**
     * 添加资产
     * @param dAssets 搜索条件
     * @return 搜索结果
     */
    @Operation(summary = "添加房间资产")
    @PostMapping("/addAsset")
    public Result<List<DAsset>> AddAsset(@RequestBody List<DAsset> dAssets){
        return dApartmentService.AddAsset(dAssets);
    }

    /**
     * 删除资产
     * @param dAssets 搜索条件
     * @return 搜索结果
     */
    @Operation(summary = "删除房间资产")
    @PostMapping("/deleteAsset")
    public Result<List<DAsset>> DeleteAsset(@RequestBody List<DAsset> dAssets){
        return dApartmentService.DeleteAsset(dAssets);
    }

    /**
     * 更改资产
     * @param dAssets 搜索条件
     * @return 搜索结果
     */
    @Operation(summary = "编辑房间资产")
    @PostMapping("/updateAsset")
    public Result<List<DAsset>> UpdateAsset(@RequestBody List<DAsset> dAssets){
        return dApartmentService.UpdateAsset(dAssets);
    }

    /**
     * 房间信息分布图数据
     * @return 搜索结果
     */
    @Operation(summary = "房间信息分布图数据")
    @PostMapping("/getApartmentAnalyze")
    public Result<List<Map>> GetApartmentAnalyze(@RequestBody DApartment dApartment){
        return dApartmentService.GetApartmentAnalyze(dApartment);
    }


    /**
     * 人员趋势图数据
     * @return 搜索结果
     */
    @Operation(summary = "人员趋势图数据")
    @PostMapping("/getApartmentTrend")
    public Result<Map> GetApartmentTrend(){
        return dApartmentService.GetApartmentTrend();
    }


    /**
     * 获取总的剩余床位数
     * @return 搜索结果
     */
    @Operation(summary = "剩余总床位数")
    @PostMapping("/getVacancyTotal")
    public Result<Map> GetVacancyTotal(@RequestBody DApartment dApartment){
        return dApartmentService.GetVacancyTotal(dApartment);
    }
}
